<?php
namespace Home\Model;
use Think\Model;
// +----------------------------------------------------------------------
// | Date:2017年1月11日
// +----------------------------------------------------------------------
// | Author: EK_熊<1439527494@qq.com>
// +----------------------------------------------------------------------
// | Description: 此文件作用于****
// +----------------------------------------------------------------------
class ProductHistoryModel extends Model{
    
    /**
     * 添加浏览记录，返回没啥意义
     * @param unknown $proid
     * @param unknown $uid
     * @return boolean|mixed|boolean|unknown|string
     * date:2017年1月11日
     * author: EK_熊
     */
    function history_set($proid,$uid){
        $map['uid'] = $uid;
        $map['pro_id'] = $proid;
        $map['created_time'] = ['between',[date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')]];
        $isExist = $this->where($map)->find();
        if (!empty($isExist))  return true;
        
        $map['created_time'] = CURRENT_TIME;
        $ret = $this->add($map);
        return $ret;
    }
    
    
    
    /**
     * 
     * @param unknown $uid   
     * @param number $model  数据模式：1今天，2昨天，3一周内，4更早（时间大于一周前）
     * @param number $limit
     * date:2017年1月11日
     * author: EK_熊
     */
    function history_get_today($uid,$limit=25){
        $dayend = date('Y-m-d 23:59:59');
        $where['created_time'] = ['between',[date('Y-m-d 00:00:00'),date('Y-m-d 23:59:59')]];
        $where['uid'] = $uid;
        $field = 'his.id as his_id,pro.id as pro_id,title';
        $ret = $this->alias('his')
        ->join('LEFT JOIN __PRODUCT__ pro ON pro.id = his.pro_id')
        ->where($where)
        ->order('created_time desc')
        ->limit(8)
        ->field($field)
        ->select();
        return $ret;
    }
    
}